function blockEvent(e){
	e.stopPropagation?e.stopPropagation():e.cancelBubble = true;
	e.preventDefault?e.preventDefault():e.returnValue = false;
}
var leftbox = document.getElementById("left");
var left = document.createElement("div");
left.style.height = "560px";
left.style.overflow = "auto";
leftbox.appendChild(left);
left.onmousedown = function(e){
	e=e||window.event;
	blockEvent(e);
};
left.onselectstart = function(e){
	e=e||window.event;
	blockEvent(e);
};
var rightbox = document.getElementById("right");
var right = document.createElement("div");
right.style.height = "560px";
right.style.overflow = "auto";
rightbox.appendChild(right);
var temp1,temp2,book_lists = {};
var i,j,o;
// 生成菜单
for( i in ability_books ){
	o = ability_books[i];
	temp1 = document.createElement("div");
	temp1.className = "class";
	temp1.data = i;
	temp1.innerHTML = "+"+i;
	temp1.onclick=function(e){
		var ele = this["cont"];
		if(ele.style.display == "block"){
			this.innerHTML = "+"+this.data;
			ele && (ele.style.display = "none");
		}else{
			this.innerHTML = "-"+this.data;
			ele && (ele.style.display="block");
		}
	};
	temp1.onmouseover = function(e){
		this.className = "class hover";
	};
	temp1.onmouseout = function(e){
		this.className = "class";
	};
	left.appendChild(temp1);
	temp1["cont"] = document.createElement("div");
	temp1["cont"].style.display = "none";
	left.appendChild(temp1["cont"]);
	// 棋艺达到激活第三身份后战术发动不失败
	// 棋艺激活第六身份后使用提升效果
	for( j in o ){
		temp2 = document.createElement("div");
		temp2.className = "class";
		temp2.data = i;
		temp2.data1 = j;
		temp2.book0 = ability_books[i][j][0];
		temp2.book1 = ability_books[i][j][1];
		temp2.book2 = ability_books[i][j][2];
		temp2.innerHTML = "&nbsp;&nbsp;"+j;
		temp2.onclick = function(e){
			var s = this.data1;
			var str = "";
			if(ability_buffs[this.data][s][0]!=="") str += '<font color="#00C8C8">棋艺达到激活第'+ability_buffs[this.data][s][0]+'身份后战术发动不失败</font><br><br>';
			if(ability_buffs[this.data][s][1]!=="") str += '<font color="#C8C8C8">'+ability_buffs[this.data][s][1]+'</font><br><br>';
			if(ability_buffs[this.data][s][2]!=="") str += '<font color="#C8C800">棋艺激活第'+ability_buffs[this.data][s][2]+'身份后使用提升效果</font><br><br>';
			if(ability_buffs[this.data][s][3]!=="") str += '<font color="#FF9696">'+ability_buffs[this.data][s][3]+'：</font><br>';
			if(ability_buffs[this.data][s][3]!=="") str += '<font color="#C8C8C8">'+advanced[ability_buffs[this.data][s][3]]+'</font><br><br>';
			if(ability_books[this.data][s]){
				str += '<font color="#FFC8C8">'+this.book0+'</font><br>';
				str += '<font color="#FFC8C8">'+this.book1+'</font><br>';
				str += '<font color="#FFC8C8">'+this.book2+'</font><br>';
			}
			right.innerHTML = str;
		};
		temp2.onmouseover = function(e){
			this.className = this.className.replace(/\shover/g,"") + " hover";
		};
		temp2.onmouseout = function(e){
			this.className = this.className.replace(/\shover/g,"");
		};
		temp1["cont"].appendChild(temp2);
		if(!book_lists[temp2.book0]) book_lists[temp2.book0]=[];
		book_lists[temp2.book0].push(temp2);
		if(!book_lists[temp2.book1]) book_lists[temp2.book1]=[];
		book_lists[temp2.book1].push(temp2);
		if(!book_lists[temp2.book2]) book_lists[temp2.book2]=[];
		book_lists[temp2.book2].push(temp2);
	}
}
// 搜索功能
var search_bt = document.getElementById("search");
search_bt.onkeyup = function(e){
	e = e || window.event;
	var flag = false;
	if(e.keyCode==13){
		var i,j;
		for( i in book_lists){
			for( j=0;j<book_lists[i].length;j++){
				book_lists[i][j].className = book_lists[i][j].className.replace(/\shighlight/g,"");
			}
		}
		if(!(/^\s*$/.test(this.value))){
			for( i in book_lists){
				if(i.indexOf(this.value)>-1){
					for( j=0;j<book_lists[i].length;j++){
						book_lists[i][j].className = book_lists[i][j].className.replace(/\shighlight/g,"") + " highlight";
						book_lists[i][j].parentNode.style.display = "block";
					}
				}
			}
		}
	}
};
